package com.dq.controller.api;

import com.dq.exception.customException.ApiException;
import com.dq.vo.Vo;
import com.dq.vo.baseVo.VO;
import com.dq.domain.category.Category;
import com.dq.service.AllService;
import com.dq.utils.TreeBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.HashSet;
import java.util.List;


/**
 * @author heshuaijun
 * @date 2019/9/1613:44
 */
@Api(description = "类别管理")
@RestController
@RequestMapping("/api/category")
public class ApiCategoryController extends AllService {

    @ApiOperation("分类列表")
    @GetMapping("/catagoryList")
    public Vo<Category.Vo> catagoryList() throws ApiException{
        List<Category> categories = categoryRepository.findByDeletedFalseAndParentCategoryIsNotNull();
        List<Category.Vo> vos = TreeBuilder.categoryBuildTree(new HashSet<>((List<Category.Vo>) VO.toVOCollection(categories)));
        return  new Vo(vos);
    }
}
